package com.codeyang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codeyang.domain.SysLog;
import com.codeyang.service.SysLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述: TO-删除标志-DO
 *
 * @author CodeYang_Site
 * @version 2021/5/24 19:16
 */
@Api(tags = "系统操作日志管理接口")
@RestController
@RequestMapping("sys/log")
public class SysLogController {

    @Autowired
    private SysLogService sysLogService;


    /**
     * 系统日志分页查询
     * Page 默认封装了 分页请求对象参数
     *
     * @param page
     * @param sysLog
     * @return
     */
    @ApiOperation("分页查询系统日志")
    @GetMapping("page")
    @PreAuthorize("hasAuthority('sys:log:page')")
    public ResponseEntity<Page<SysLog>> loadSysLog(Page<SysLog> page, SysLog sysLog) {
        Page<SysLog> sysLogPage = sysLogService.page(page, new LambdaQueryWrapper<SysLog>()
                .like(StringUtils.hasText(sysLog.getUsername()), SysLog::getUsername, sysLog.getUsername())
                .like(StringUtils.hasText(sysLog.getOperation()), SysLog::getOperation, sysLog.getOperation())
                .orderByDesc(SysLog::getCreateDate)
        );
        return ResponseEntity.ok(sysLogPage);
    }
}
